package com.visitorspecials.tankbattle.server;

import java.util.Date;
import java.util.*;

public abstract class Actor
{

	protected Vector2 _location;

	protected float _heading;

	protected String _textureName;

	protected ArrayList<Actor> _list;

	/*	 * 
	 * protected float _height;
	 * 
	 * protected float _width;
	 */

	protected float _size;

	public Vector2 getLocation()
	{
		return this._location;
	}

	public void setLocation(Vector2 loc)
	{
		this._location = loc;
	}

	public void setHeading(float heading)
	{
		this._heading = heading;
	}

	/*
	 * public float getHeight() { return this._height; }
	 * 
	 * public float getWidth() { return this._width; }
	 */

	public float getSize()
	{
		return this._size;
	}

	public String getTextureName()
	{
		return this._textureName;
	}

	public void setTextureName(String textureName)
	{
		this._textureName = textureName;
	}
	
	public float getHeading()
	{
		return this._heading;
	}

	public Boolean isColidingWith(Actor a)
	{
		/*
		 * float xDis = Math.abs(this._location.x-a._location.x); float yDis =
		 * Math.abs(this._location.y-a._location.y); float distance = (float)
		 * Math.sqrt(Math.pow(xDis, 2) + Math.pow(yDis, 2)); float angle =
		 * (float) Math.atan(yDis/xDis);
		 * 
		 * float realDis; float thisAdjacent; float aAdjacent;
		 * 
		 * if(angle > Math.PI/4+(this._heading%Math.PI/4)) { thisAdjacent =
		 * this._height/2; } else { thisAdjacent = this._width/2; }
		 * 
		 * if(angle > Math.PI/4+(a._heading%Math.PI/4)) { aAdjacent =
		 * a._height/2; } else { aAdjacent = a._width/2; }
		 * 
		 * realDis = (float) (thisAdjacent/Math.cos(angle) +
		 * aAdjacent/Math.cos(angle));
		 * 
		 * if(realDis>=distance) { return true; } else return false;
		 */

		Vector2 diffVector = Vector2
				.subtract(this._location, a.getLocation());
		float minDistance = this._size + a.getSize();
		if (Vector2.magnitude(diffVector) <= minDistance)
		{
			return true;
		}
		else
			return false;
	}

	public Actor(String textureName, Vector2 loc, float size,
			ArrayList<Actor> list)
	{
		this._textureName = textureName;
		this._location = loc;
		this._size = size;
		this._list = list;
	}

	public void update(float elapsed)
	{

	}

	public void removeSelfFromList()
	{
		_list.remove(this);
	}

	@Override
	public String toString()
	{
		return String.format("::%s:%f:%f:%f:%f", this._textureName,
				this._location.x, this._location.y, this._heading, this._size);
	}
}
